from selenium.webdriver.common.by import By

from page_object.pages.BasePage import BasePage


class LoginPage(BasePage):
    _iv_action_back = (By.ID, 'iv_action_back')                 #叉号
    _login_account = (By.ID, 'login_account')                   #登陆手机号或者邮箱
    _login_password = (By.ID, 'login_password')                 #登陆密码
    _button_next = (By.ID, 'button_next')                       #登陆按钮
    _login_without_password = (By.ID, 'login_without_password') #验证码快捷登陆
    _register_phone_number = (By.ID, 'register_phone_number')   #验证码登陆输入手机号
    _register_code = (By.ID, 'register_code')                   #验证码登陆输入验证码
    _tv_login_with_account = (By.ID, 'tv_login_with_account')   #邮箱手机号密码登陆
    _register_code_text = (By.ID, 'register_code_text')         #发送验证码
    _tv_forget_password = (By.ID, 'tv_forget_password')          #忘记密码
    _weiXin_login = (By.ID, 'weixin_login')                     #微信登陆
    _error_msg = (By.ID, 'md_content')                          #错误提示内容

    def loginByWX(self):
        return self
    def loginByMSG(self, phone, code):
        return self

    def loginByPassword(self, account, password):
        # self.find(self._login_account).send_keys(account)
        # self.find(self._login_password).send_keys(password)
        # self.find(self._button_next).click()
        self.loadSteps("../data/LoginPage.yaml", "loginByPassword", var1=account, var2=password)
        return self

    def loginSuccessByPassword(self, account, password):
        from page_object.pages.MainPage import MainPage
        return MainPage()

    def back(self):
        self.find(self._iv_action_back).click()
        from page_object.pages.MyPage import MyPage
        return MyPage

    def getErrorMsg(self):
        msg = self.find(self._error_msg).text
        self.find_by_xpath('确定').click()
        return msg
